﻿<html>
<head>
</head>
<body>
	<div>fcdmlsvcjkoflcrhsnng : 214ae76ae3b3d8da219f3cb5407ae0cd</div>
	<div id="result"></div>
	<embed type="application/NT120Plugin" id="testPlugin" style="width:0px; height:0px;" />
	<div>
		<button onclick="initKey()">初始化Key</button>
	</div>
	<div>
		USBKey登录密码：<input id="txtKeyPassword" maxlength="20" size="10" />
		<button onclick="testLogin()">测试登录Key</button>
	</div>
	<button onclick="testEncrypt()">测试加密</button>

	<script type="text/javascript">
		var plugin = document.getElementById("testPlugin");

		var usbKeyNumber;
		function initKey() {
			let res = plugin.initKey()
			if (res === 0) {
				res = plugin.findKey();
				if (res === 0) {
					res = plugin.getKeyNumber();
					if (!res) {
						res = "读取USBKey的编号失败！";
					} else {
						usbKeyNumber = res;
					}
				} else {
					res = "未查找到任何USBKey！";
				}
			} else {
				res = "USBKey注册或初始化失败！";
			}
			document.getElementById("result").innerHTML = `Key:${res}`;
		}

		function testLogin(showMsg) {
			let pw = document.getElementById("txtKeyPassword").value;
			let msg = '';
			let res = -1;
			if (usbKeyNumber) {
				res = plugin.findKey();
				if (res === 0) {
					res = plugin.loginKey(pw);
					if (res === 0) {
						msg = `<br/>登录成功！`;
					} else {
						msg = `<br/>登录失败！`;
					}
				}
			} else {
				msg = '请先初始化USBKey！';
			}
			showMsg!==false && document.getElementById("result").insertAdjacentHTML('beforeend', msg);
			return res;
		}

		function testEncrypt() {
			if (usbKeyNumber) {
				let res = plugin.findKey();
				if (res === 0) {
					res = testLogin(false);
					if (res === 0) {
						res = plugin.encrypt('fcdmlsvcjkoflcrhsnng');
						document.getElementById("result").insertAdjacentHTML('beforeend', `<br/>Random:${res}`);
					} else {
						alert('登录USBKey失败！');
					}
				}
			} else {
				alert('请先初始化USBKey！');
			}

		}

		function onNTPluginError(msg) {
			debugger;
		}
	</script>
</body>
</html>